//
//  MenuScreen.cpp
//  match2
//
//  Created by Tri Vo on 7/8/13.
//
//

#include "MenuScreen.h"



using namespace cocos2d;


CCScene *MenuScreen::scene() {
    CCScene *scene = CCScene::create();
    
    MenuScreen *layer = MenuScreen::create();
    scene->addChild(layer);
    
    return scene;
}



bool MenuScreen::init() {
    if (!CCLayer::init()) {
        return false;
    }
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    CCLabelTTF *mainTitle = CCLabelTTF::create("Match 2", GameController::getFontNameForTitle(), GameController::getFontSizeForTitle());
    mainTitle->setPosition(ccp(size.width/2, size.height/2 + 120));
    this->addChild(mainTitle, 1);
    // Menu
    CCMenuItem *menuStartGame = CCMenuItemFont::create("Start game", this, menu_selector(MenuScreen::enterGameScreen));
    CCMenuItem *menuGuide = CCMenuItemFont::create("Guide", this, menu_selector(MenuScreen::enterGuideScreen));
    CCMenuItem *menuAbout = CCMenuItemFont::create("About", this, menu_selector(MenuScreen::enterAboutScreen));
    CCMenuItem *menuExit = CCMenuItemFont::create("Exit", this
                                                  , menu_selector(MenuScreen::exitGame));
    CCMenu *menu = CCMenu::create(menuStartGame, menuGuide,menuAbout, menuExit, NULL);
    menu->alignItemsVerticallyWithPadding(15);
    
    menu->setPosition(ccp(size.width/2, size.height/2));
    
    this->addChild(menu, 1);
    
    return true;
}

#pragma mark - Screen Methods

void MenuScreen::enterGameScreen(CCObject* sender) {
    SoundManager::getInstance()->playSound(SOUND_MENU_CLICK, false);
    CCDirector::sharedDirector()->replaceScene(CCTransitionFade::create(0.5f, GameScreen::scene()));
}

void MenuScreen::enterAboutScreen(CCObject *sender) {
    SoundManager::getInstance()->playSound(SOUND_MENU_CLICK, false);
    GameController::pushScene(AboutScreen::scene());
}

void MenuScreen::enterGuideScreen(CCObject *sender) {
    SoundManager::getInstance()->playSound(SOUND_MENU_CLICK, false);
    GameController::pushScene(GuideScreen::scene());
}